<style>
    .modal_searchnewgood{ }
    .modal_searchnewgood p{margin: 5px 0}
    .modal_modal_searchnewgoodbox{ padding:10px;}
</style>
<div class="modal_searchnewgood" style="display:none">
    <div class="modal_modal_searchnewgoodbox">
        <form onsubmit="return false;">
            <p style="text-align: center;"><img src="" id="newgood_showthumb" onerror="this.src='{MODULE_URL}template/resources/img/002.png'" style="width:120px;height:120px;"/><input type="hidden" id="newgood_thumb" /></p>
            <p><input type="text" id="newgood_title" placeholder="商品名称" autocomplete="off" class="layui-input"/></p>
            <p><select id="newgood_pcate" lay-verify="required" lay-ignore="" class="form-control">
                <option value="0" selected>分类</option>
                {loop $goodpcatelist $row}
                <option value="{$row['id']}">{$row['title']}</option>
                {/loop}
            </select></p>
            <p><input type="text" id="newgood_goodsn" placeholder="条码" autocomplete="off" class="layui-input"/></p>
            <p><input type="text" id="newgood_price" placeholder="价格" autocomplete="off" class="layui-input"/></p>
        </form>
    </div>
</div>
<script>
    function fun_searchgoodsn(keyword){
        console.log(keyword);
        if(keyword.length<6){
            layer.closeAll();
            return false;
        }
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'searchgoodbysn'))}",{keyword:keyword},function(returnstr){
            console.log(returnstr);
            layer.close(index2);
            var result=eval("("+returnstr+")");
            if(result.success){
                modal_shownewgood(result.goods);
            }else{
                layer.msg(result.msg,{icon:2,time:1500});
                return;
            }
        });
    }
    function modal_shownewgood(goods){
        layer.open({
            type: 1,
            area:"400px",
            title:"添加新商品",
            content:$(".modal_searchnewgood").show(),
            btn:['确认','取消'],
            btn1:function(indexs,layero){
                if($("#newgood_title").val().length<1){
                    layer.msg("商品名称不能为空",{icon:2,time:1500});
                    return;
                }
                var update={
                    "title":$("#newgood_title").val(),
                    "goodsn":$("#newgood_goodsn").val(),
                    "price":$("#newgood_price").val(),
                    "pcate":$("#newgood_pcate").val(),
                    "thumb":$("#newgood_thumb").val(),
                };
                layer.close(indexs);
                var index2=layer.load(1, {shade: [0.1,'#fff']});
                $.post("{php echo $this->createMobileUrl('index',array('op'=>'addnewgood'))}",update,function(returnstr){
                    console.log(returnstr);
                    layer.close(index2);
                    var result=eval("("+returnstr+")");
                    if(result.success){
                        $("#Txt_search").val($("#newgood_goodsn").val());
                        $("#btnsearch").click();
                    }else{
                        layer.msg(result.msg,{icon:2,time:1500});
                        return;
                    }
                });
            },
            success: function(layero, index){
                $("#newgood_title").val(goods.title);
                $("#newgood_goodsn").val(goods.goodsn);
                $("#newgood_price").val(goods.price);
                $("#newgood_thumb").val(goods.thumb);
                $("#newgood_pcate").val(0);
                $("#newgood_showthumb").attr("src",goods.thumb);
            },
            end:function(){
                $(".modal_searchnewgood").hide();
            }
        });
    }
</script>